package com.smc.dao;

import com.smc.mapper.SchoolInfoMapper;
import com.smc.model.SchoolInfo;
import com.smc.service.impl.SchoolInfoImpl;
import com.smc.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.EOFException;

@Service
public class SchoolInfoDao implements SchoolInfoImpl {
    @Autowired
    SchoolInfoMapper schoolInfoMapper;

    @Override
    public void insert(SchoolInfo schoolInfo) {
        schoolInfoMapper.insert(schoolInfo);
    }

    @Override
    public void deleteByModel(SchoolInfo schoolInfo) throws EOFException {
        if (BaseUtil.isNull(schoolInfo) || BaseUtil.isNull(schoolInfo.getId()) && BaseUtil.isNull(schoolInfo.getSchoolName())){
            throw new EOFException("Id不能为空或name不能为空");
        }else {
            schoolInfoMapper.deleteByModel(schoolInfo);
        }
    }

    @Override
    public void deleteById(Integer Id) {
        schoolInfoMapper.deleteById(Id);
    }

    @Override
    public SchoolInfo selectById(Integer Id) {
        return schoolInfoMapper.selectById(Id);
    }

    @Override
    public void updateByModel(SchoolInfo schoolInfo) {
        schoolInfoMapper.updateByModel(schoolInfo);
    }
}